package com.atguigu.stgy.admin.controller;

import com.atguigu.stgy.admin.service.PaymentTypeService;
import com.atguigu.stgy.model.entity.PaymentType;
import com.atguigu.stgy.model.result.R;
import com.atguigu.stgy.model.result.ResultCodeEnum;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/admin/payment")
@Tag(name = "支付方式")
public class PaymentTypeController {
    @Resource
    PaymentTypeService paymentTypeService;
    @GetMapping("list")
    @Operation(summary = "查询所有支付方式")
    public R<List<PaymentType>> list(){
        return R.ok(paymentTypeService.list());
    }

    // http://localhost:8080/admin/payment/deleteById?id=11


    @Operation(summary = "删除支付方式")
    @DeleteMapping("deleteById")
    public  R deleteById(@Parameter(name = "id",description = "支付方式id",in = ParameterIn.QUERY)
                                                @RequestParam(value = "id") Long id){
        boolean b = paymentTypeService.removeById(id);
        return b?R.ok():R.fail(ResultCodeEnum.FAIL);

    }

    //  http://localhost:8080/admin/payment/saveOrUpdate

    @PostMapping("saveOrUpdate")
    @Operation(summary = "新增支付方式")
    public R saveOrUpdate(@RequestBody  PaymentType paymentType){//接收参数
        boolean b = paymentTypeService.saveOrUpdate(paymentType);
        return b?R.ok():R.fail(ResultCodeEnum.FAIL);
    }

}
